# this is run in a chrooted environment
import glob
from os.path import isdir, basename

localdirnames = set()

for localdir in glob.glob('/usr/share/locale/*'):
    if not isdir(localdir):
      continue
    localdirnames.add(basename(localdir))

removelocales = localdirnames.difference(set(config.get('locales')))
print sorted(list(removelocales))
for local in removelocales:
    print 'Removing','/usr/share/locale/{0}'.format(local)
    
    yum.remove_files('/usr/share/locale/{0}'.format(local))

# remove kernel modules

removekmods = '''sound drivers/media drivers/hwmon drivers/video drivers/char
net/atm net/bluetooth net/sched net/sctp net/bridge
net/rds net/l2tp net/decnet net/netfilter net/ipv4 net/ipv6
drivers/watchdog drivers/target drivers/rtc drivers/input/joystick
drivers/bluetooth drivers/hid drivers/edac drivers/staging
drivers/usb/serial drivers/usb/host drivers/usb/misc
fs/ocfs2 fs/ceph fs/nfsd fs/ubifs fs/nilfs2
arch/x86/kvm'''

for kmodpath in removekmods.split():
  yum.remove_files('/lib/modules/*/kernel/%s' % kmodpath)
  
yum.remove_files('/lib/modules/*/{build,source,*.map}')
## NOTE: depmod gets re-run after cleanup finishes

## remove generated locales - anaconda >=16.x builds them at runtime
yum.removefrom('glibc-common', '/usr/lib/locale/*')
yum.remove_files('/usr/lib/locale/locale-archive')

# remove docs
yum.remove_files('/usr/share/doc /usr/share/info /usr/share/man /usr/share/gnome'.split(' '))

# remove mimetypes
yum.remove_files('/usr/share/mime/application /usr/share/mime/audio /usr/share/mime/image'.split(' '))
yum.remove_files('/usr/share/mime/inode /usr/share/mime/message /usr/share/mime/model'.split(' '))
yum.remove_files('/usr/share/mime/multipart /usr/share/mime/packages /usr/share/mime/text'.split(' '))
yum.remove_files('/usr/share/mime/video /usr/share/mime/x-content /usr/share/mime/x-epoc'.split(' '))


## remove unwanted systemd services
yum.removefrom('systemd-units', '/lib/systemd/system/*plymouth*')
yum.removefrom('systemd-units', '/lib/systemd/system/kexec*')
yum.removefrom('systemd-units', '/lib/systemd/system/local-fs.target.wants/media.mount')
yum.removefrom('systemd-units', '/lib/systemd/system/media.mount')
yum.removefrom('systemd-units', '/lib/systemd/system/quota*.service')
yum.removefrom('systemd-units', '/lib/systemd/system/systemd-remount-api-vfs.service')
yum.removefrom('ConsoleKit', '/lib/systemd/system/*')
yum.removefrom('initscripts', '/lib/systemd/system/fedora*')
yum.removefrom('initscripts', '/lib/systemd/fedora*')
yum.removefrom('lvm2', '/lib/systemd/system/*')
yum.removefrom('mdadm', '/lib/systemd/system/*')


yum.removefrom('hwdata', '/etc/*')
yum.removefrom('hwdata', '/usr/share/hwdata/oui.txt')
yum.removefrom('hwdata', '/usr/share/hwdata/pnp.ids')

## no perl (it gets pulled in on ppc)
yum.strip_package_files('perl*')

## no sound support, thanks
yum.strip_package_files('alsa* flac gstreamer-tools libsndfile pulseaudio* sound-theme-freedesktop midisport-firmware'.split(' '))

## no fancy video, either
yum.strip_package_files('libcrystalhd crystalhd-firmware ivtv-firmware cx18-firmware'.split(' '))
yum.strip_package_files('mesa-dri-drivers llvm-libs'.split(' '))

## we don't use plymouth
yum.strip_package_files('plymouth*')
#removefrom ${product.name}-logos /usr/share/plymouth/*

## we don't create new initramfs/bootloader conf inside anaconda
## (that happens inside the target system after we install dracut/grubby)
yum.strip_package_files('dracut* grubby'.split(' '))

## we don't run SELinux (not in enforcing, anyway)
yum.strip_package_files('checkpolicy selinux-policy libselinux-utils'.split(' '))

## anaconda has its own repo files
yum.strip_package_files('fedora-release fedora-release-rawhide'.split(' '))


yum.strip_package_files('avahi-autoipd coreutils-libs curl dash db4-utils diffutils file'.split())
yum.strip_package_files('fipscheck genisoimage gnome-python2 info iptables isomd5sum'.split())
yum.strip_package_files('jasper-libs libIDL libXt libXxf86misc libXxf86vm'.split())
yum.strip_package_files('libasyncns libcroco libdaemon libevent libhbaapi libhbalinux'.split())
yum.strip_package_files('libmcpp libpcap librsvg2 libtiff libutempter linux-atm-libs'.split())
yum.strip_package_files('lvm2-libs m4 mailx makebootfat mcpp'.split())
yum.strip_package_files('mingetty mobile-broadband-provider-info pkgconfig ppp pth'.split())
yum.strip_package_files('rmt rpcbind shared-mime-info squashfs-tools system-config-firewall-base'.split())
yum.strip_package_files('tigervnc-license ttmkfdir xml-common xorg-x11-font-utils'.split())
yum.strip_package_files('xorg-x11-server-common yum-utils'.split())

yum.remove_files('/usr/share/mime/application')

yum.remove_files('/usr/share/mime/audio')
yum.remove_files('/usr/share/mime/image')
yum.remove_files('/usr/share/mime/inode')
yum.remove_files('/usr/share/mime/message')
yum.remove_files('/usr/share/mime/model')
yum.remove_files('/usr/share/mime/multipart')
yum.remove_files('/usr/share/mime/packages')
yum.remove_files('/usr/share/mime/text')
yum.remove_files('/usr/share/mime/video')
yum.remove_files('/usr/share/mime/x-content')
yum.remove_files('/usr/share/mime/x-epoc')

## Configure systemd to start anaconda
yum.remove_files('/etc/systemd/system/default.target')
yum.remove_files('/etc/systemd/system/default.target.wants/*')
#symlink /lib/systemd/system/anaconda.target etc/systemd/system/default.target
## disable firewall 
#chkconfig iptables off
#chkconfig  ip6tables off
